<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="姓名" prop="scTcName">
          <el-input
            v-model="queryParams.scTcName"
            placeholder="请输入姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="电话" prop="scTcPhone">
          <el-input
            v-model="queryParams.scTcPhone"
            placeholder="请输入电话"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="邮箱" prop="scTcEmail">
          <el-input
            v-model="queryParams.scTcEmail"
            placeholder="请输入邮箱"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="教师职务" prop="scTcWork">
          <el-input
            v-model="queryParams.scTcWork"
            placeholder="请输入教师职务"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="面向专业/学生" prop="scTcZy">
          <el-input
            v-model="queryParams.scTcZy"
            placeholder="请输入面向专业/学生"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="课题名称" prop="scTcKt">
          <el-input
            v-model="queryParams.scTcKt"
            placeholder="请输入课题名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="教师所在系" prop="scTcSzx">
          <el-input
            v-model="queryParams.scTcSzx"
            placeholder="请输入教师所在系"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="课题来源" prop="scTcLy">
          <el-input
            v-model="queryParams.scTcLy"
            placeholder="请输入课题来源"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="
  成果类别" prop="scTcCg">
          <el-input
            v-model="queryParams.scTcCg"
            placeholder="请输入
  成果类别"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="课题完成途径" prop="scTcWctj">
          <el-input
            v-model="queryParams.scTcWctj"
            placeholder="请输入课题完成途径"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="设计类别" prop="scTcLb">
          <el-input
            v-model="queryParams.scTcLb"
            placeholder="请输入设计类别"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="备注" prop="scTcBz">
          <el-input
            v-model="queryParams.scTcBz"
            placeholder="请输入备注"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
       
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="tcList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="30" align="center" />
        <el-table-column label="id" align="center" prop="scTcId" width="40" />
        <el-table-column label="姓名" align="center" prop="scTcName" width="70" />
        <el-table-column label="电话" align="center" prop="scTcPhone"  width="110"/>
        <el-table-column label="邮箱" align="center" prop="scTcEmail" width="100" />
        <el-table-column label="职务" align="center" prop="scTcWork" width="70" />
        <el-table-column label="面向专业" align="center" prop="scTcZy" width="100"/>
        <el-table-column label="课题名称" align="center" prop="scTcKt" />
        <el-table-column label="教师所在系" align="center" prop="scTcSzx" width="90" />
        <el-table-column label="课题来源" align="center" prop="scTcLy"  width="90"/>
        <el-table-column label="成果类别" align="center" prop="scTcCg" width="80" />
        <el-table-column label="完成途径" align="center" prop="scTcWctj" width="90" />
        <el-table-column label="设计类别" align="center" prop="scTcLb"  width="90" />
        <el-table-column label="学生人数" align="center" prop="scTcSt"  width="90" />
        <el-table-column label="备注" align="center" prop="scTcBz" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope" #default="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 添加或修改【请填写功能名称】对话框 -->
      <el-dialog :title="title" v-model="open" width="500px" :append-to-body="true">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="姓名" prop="scTcName">
            <el-input v-model="form.scTcName" placeholder="请输入姓名" />
          </el-form-item>
          <el-form-item label="电话" prop="scTcPhone">
            <el-input v-model="form.scTcPhone" placeholder="请输入电话" />
          </el-form-item>
          <el-form-item label="邮箱" prop="scTcEmail">
            <el-input v-model="form.scTcEmail" placeholder="请输入邮箱" />
          </el-form-item>
          <el-form-item label="教师职务" prop="scTcWork">
            <el-input v-model="form.scTcWork" placeholder="请输入教师职务" />
          </el-form-item>
          <el-form-item label="面向专业/学生" prop="scTcZy">
            <el-input v-model="form.scTcZy" placeholder="请输入面向专业/学生" />
          </el-form-item>
          <el-form-item label="课题名称" prop="scTcKt">
            <el-input v-model="form.scTcKt" placeholder="请输入课题名称" />
          </el-form-item>
          <el-form-item label="教师所在系" prop="scTcSzx">
            <el-input v-model="form.scTcSzx" placeholder="请输入教师所在系" />
          </el-form-item>
          <el-form-item label="课题来源" prop="scTcLy">
            <el-input v-model="form.scTcLy" placeholder="请输入课题来源" />
          </el-form-item>
          <el-form-item label="
  成果类别" prop="scTcCg">
            <el-input v-model="form.scTcCg" placeholder="请输入
  成果类别" />
          </el-form-item>
          <el-form-item label="课题完成途径" prop="scTcWctj">
            <el-input v-model="form.scTcWctj" placeholder="请输入课题完成途径" />
          </el-form-item>
          <el-form-item label="设计类别" prop="scTcLb">
            <el-input v-model="form.scTcLb" placeholder="请输入设计类别" />
          </el-form-item>
          <el-form-item label="备注" prop="scTcBz">
            <el-input v-model="form.scTcBz" placeholder="请输入备注" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { listTc, getTc, delTc, addTc, updateTc } from "../../api/sc/tc";
  
  export default {
    name: "Tc",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        tcList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          scTcName: null,
          scTcPhone: null,
          scTcEmail: null,
          scTcWork: null,
          scTcZy: null,
          scTcKt: null,
          scTcSzx: null,
          scTcLy: null,
          scTcCg: null,
          scTcWctj: null,
          scTcLb: null,
          scTcBz: null,
          scTcSt: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          scTcName: [
            { required: true, message: "姓名不能为空", trigger: "blur" }
          ],
          scTcPhone: [
            { required: true, message: "电话不能为空", trigger: "blur" }
          ],
          scTcZy: [
            { required: true, message: "面向专业/学生不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listTc(this.queryParams).then(response => {
          this.tcList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          scTcId: null,
          scTcName: null,
          scTcPhone: null,
          scTcEmail: null,
          scTcWork: null,
          scTcZy: null,
          scTcKt: null,
          scTcSzx: null,
          scTcLy: null,
          scTcCg: null,
          scTcWctj: null,
          scTcLb: null,
          scTcBz: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.scTcId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const scTcId = row.scTcId || this.ids
        getTc(scTcId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改【请填写功能名称】";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.scTcId != null) {
              updateTc(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addTc(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const scTcIds = row.scTcId || this.ids;
        this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + scTcIds + '"的数据项？').then(function() {
          return delTc(scTcIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/tc/export', {
          ...this.queryParams
        }, `tc_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  